﻿using System.Collections.Generic;
using System.Net;
using Provausio.Server.Nzb.Poller.Object.Client;

namespace Provausio.Server.Nzb.Poller.Data.Source
{
    public class SabNzbdPingSource : PingApiOperationBase
    {
        protected override string ApiUri
        {
            get { return Config["SabNzbdUri"]; }
        }

        protected override string ApiFormat
        {
            get { return "api"; }
        }

        public SabNzbdPingSource()
            : base("SabNzbd")
        {
            Parameters.Add(new KeyValuePair<string, object>("apikey", Config["SabNzbdApiKey"]));
            Parameters.Add(new KeyValuePair<string, object>("mode", "version"));
            Parameters.Add(new KeyValuePair<string, object>("output", "json"));
        }

        public override bool IsAlive()
        {
            var result = MakeCall<SabNzbdPingResponse>();
            return result != null && result.StatusCode == HttpStatusCode.OK;
        }
    }
}
